package com.baofu.paycore.common.exception;

import com.system.commons.exception.ErrorCode;
import lombok.Getter;

/**
 * User: LZQ
 * <p>
 * 注意：错误码定义规则，错误码长度不能超过32位
 * </p>
 * 服务层异常码
 */
@Getter
public enum ServiceErrorCode implements ErrorCode {

    /**
     * 金额超限
     */
    OVERRUN_REFUND_AMOUNT("OVERRUN_REFUND_AMOUNT", "金额超限"),

    /**
     * 重复撤销、冲正
     */
    RE_CANCEL_OR_EC("RE_CANCEL_OR_EC","重复处理"),

    /**
     * 订单状态不为支付成功
     */
    ORDER_STATUS_NOT_SUCCESS("ORDER_STATUS_NOT_SUCCESS", "订单状态不为支付成功"),

    /**
     * 订单状态为支付成功
     */
    ORDER_STATUS_SUCCESS("ORDER_STATUS_SUCCESS", "订单状态为支付成功"),

    /**
     * 订单推进异常
     */
    PROCESS_ORDER_ERROR("PROCESS_ORDER_ERROR","订单推进异常"),

    /**
     * 支付类型不合法
     */
    SERVICE_CODE_ERROR("SERVICE_CODE_ERROR", "支付类型不合法"),

    /**
     * 资金单类型
     */
    FUND_TYPE_ERROR("FUND_TYPE_ERROR", "资金单类型不合法"),

    WITHDRAW_FUND_INFO_NULL("WITHDRAW_FUND_INFO_NULL", "提现资金单信息为空"),

    WITHDRAW_BANK_INFO_NULL("WITHDRAW_BANK_INFO_NULL", "提现银行资金单信息为空"),

    /**
     * 订单已经全部退款
     */
    PAY_ORDER_REFUND_ALL_AMOUNT("PAY_ORDER_REFUND_ALL_AMOUNT","订单已经全部退款"),

    /**
     * 订单未支付成功,不能退款
     */
    PAY_ORDER_NOT_SUCCESS("PAY_ORDER_NOT_SUCCESS","订单未支付成功,不能退款"),

    /**
     * 退款原单交易类型异常,不支持退款
     */
    ORIG_ORDER_SERVICE_CODE_ERROR("ORIG_ORDER_SERVICE_CODE_ERROR","退款原单交易类型异常,不支持退款"),

    /**
     * 退款币种与原支付币种不一致
     */
    REFUND_PAY_CCY_NOT_EQUALS("REFUND_PAY_CCY_NOT_EQUALS", "退款币种与原支付币种不一致"),

    /**
     * 退款金额超过可退款金额
     */
    REFUND_AMT_EXCEED_REFUNDABLE_AMT("REFUND_AMT_EXCEED_REFUNDABLE_AMT", "退款金额超过原单可退款金额"),
    ;

    /**
     * 错误编码
     */
    private String errorCode;

    /**
     * 错误描述
     */
    private String errorDesc;

    ServiceErrorCode(String code, String desc) {
        this.errorCode = code;
        this.errorDesc = desc;
    }

    /**
     * 根据代码获取枚举
     *
     * @param code      错误码
     * @return          错误码枚举
     */
    public static ServiceErrorCode getByCode(String code) {
        for (ServiceErrorCode serviceErrorCode : ServiceErrorCode.values()) {
            if (serviceErrorCode.getErrorCode().equalsIgnoreCase(code)) {
                return serviceErrorCode;
            }
        }
        return null;
    }

    /**
     * 设置错误描述信息
     *
     * @param errorMsg 错误信息
     */
    @Override
    public void setErrorDesc(String errorMsg) { }
}
